package com.bilgeadam.hibernate.program;

import java.util.Set;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

/**
 * 
 * @author Bora SAYINER
 * @since Nov 15, 2014 3:57:55 PM
 * @version 1.0.0
 */
public class Driver {

	public static void main(String[] args) {
		SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
		Session session = sessionFactory.openSession();
		Transaction transaction = session.beginTransaction();
		
			Department department = (Department) session.get(Department.class, 2L);
			System.out.println(department);
			
			
			// Employee employee = new Employee();
			// employee.setFirstName("Nigar");
			// employee.setLastName("Durmuş");
			// {
			// Department it = (Department) session.get(Department.class, 2L);
			// employee.setDepartment(it);
			//
			// }
			// session.save(employee);
			//
			// Employee employee = (Employee) session.get(Employee.class, 3L);
			// System.out.println(employee);
			// System.out.println(employee.getVehicle());
			//
			// Vehicle vehicle = (Vehicle) session.get(Vehicle.class, 1L);
			// Employee employee = vehicle.getEmployee();
			// System.out.println(employee);
		
		transaction.commit();
		session.close();
		Set<Employee> employees = department.getEmployees();
		for (Employee employee : employees) {
			System.out.println(employee);
		}
		sessionFactory.close();
	}
}
